package itheima.com.Test;

import java.io.*;
import java.util.ArrayList;

public class Test5 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Teacher t1 = new Teacher("杨青", "28");
        Teacher t2 = new Teacher("刘铭", "26");
        Teacher t3 = new Teacher("李悦", "29");
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("b.txt"));
      /*  oos.writeObject(t1);
        oos.writeObject(t2);
        oos.writeObject(t3);
        oos.close();*/
        ArrayList<Teacher> list = new ArrayList<>();
        list.add(t1);
        list.add(t2);
        list.add(t3);

        oos.writeObject(list);
        oos.close();


        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("b.txt"));
      /*  Object obj;
        while ((obj=ois.readObject())!=null){
            System.out.println(obj);
        }*/


//      while (true){
//          try {
//              Object obj = ois.readObject();
//              System.out.println(obj);
//          } catch (EOFException e) {
//              break;
//          }
//      }

        ArrayList<Teacher> list2 =(ArrayList<Teacher>) ois.readObject();
        for (Teacher teacher : list2) {
            System.out.println(teacher);
        }
        oos.close();
    }
}
